<template>
  <div class="page">
    <el-container>
      <el-aside width="260px">
        <div class="logo">时光网</div>
        <el-menu class="el-menu" background-color="#00000000" text-color="#ffffffff">
          <el-submenu
              v-for="(groupItem,i) in menus" :key="groupItem.groupCode"
              class="el-submenu" :index="i+''" background-color="#00000000" text-color="#ffffffff" style="text-align: left;">
            <template slot="title">
              <i class="el-icon-menu" style="color:#fff;"></i>
              <span>{{groupItem.groupName}}</span>
            </template>
            <el-menu-item-group class="el-submenu">
              <el-menu-item :index="i+'-'+j" v-for="(menuItem,j) in groupItem.items" :key="menuItem.id"
                            @click="menuClick(menuItem)">
                {{menuItem.menuName}}
              </el-menu-item>
            </el-menu-item-group>

          </el-submenu>
          <el-submenu index="exit"  background-color="#00000000" text-color="#ffffffff" style="text-align: left;">
            <template slot="title">
              <i class="el-icon-close" style="color:#fff;"></i>
              <span @click="gotoLogin()">退出登录</span>
            </template>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="title">影片库管理系统</div>
          <div class="user right">当前登录：admin</div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
        <el-footer>
          <div class="text">企业级开发技术-WEB客户端开发技术课程案例-实验15 ©NIIT-SCS</div>
        </el-footer>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //菜单数组
      menus: [],
      //当前用户
      currentUser: ""
    }
  },
  methods: {
    gotoLogin() {
      localStorage.clear();
      this.$router.push("/login");
    },
    loadMenus() {
      this.$http({
        url: '/api/admin/menus'
      }).then((response) => {
        if (response.status == 200) {
          console.log("获取菜单成功", response.data);
          this.menus = response.data;
        }
      })
    },
    menuClick(menu) {
      console.log("菜单点击", menu);
      this.$router.push('/admin/' + menu.href);
    }
  },
  mounted() {
    this.currentUser = localStorage.getItem("usertoken");
    this.loadMenus();
  }
}
</script>

<style scoped="scoped">
.page {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.el-header,
.el-footer {
  background-color: #fff;

  color: #999;
  line-height: 60px;
  display: flex;
}

.el-header {
  border-bottom: 0.6px solid rgba(99, 99, 99, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.el-footer {
  border-top: 0.6px solid rgba(99, 99, 99, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.el-aside {
  background: linear-gradient(to bottom, #fb404b 0, rgba(187, 5, 2, .6) 100%);
  color: #fff;
  text-align: center;
}

.el-main {
  background-color: #fff;
  color: #333;
  height: calc(100vh - 120px);
}

.logo {
  font-size: 230%;
  font-weight: 600;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 60px;
  width: 96%;
  border-bottom: 0.5px solid rgba(200, 200, 200, 0.7);
}

.title {
  font-size: 110%;
  margin-left: 30px;
}

.right {
  flex: 1;
  text-align: right;
  padding-right: 20px;
}

.el-menu{

}

</style>
